package com.ymatou.iapi.godmch.testcase;


import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.setInteractionStateBean;
import com.ymatou.iapi.godmch.service.setInteractionStateCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.interactionstate;
import com.ymttest.database.model.godmch.interactionstateExample;
import com.ymttest.database.sqlwapper.godmch.interactionstateWapper;
import com.ymttest.utils.TestDataManager;
/**
*设置前端交互状态
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_setInteractionState{
	private static setInteractionStateBean bean;
	private static setInteractionStateCall call;
	private  interactionstateExample interactionstateExample=new interactionstateExample();
	private  interactionstateWapper interactionstateWapper=new interactionstateWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置前端交互状态");
	}

	@Before
	public void caseUp() {
		bean=new setInteractionStateBean();
		call=new setInteractionStateCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setInteractionState_001() {
		Logger.start(true,"正例-设置前端交互状态-返回成功");
		try {
			//创建渠道
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			bean.setMchId(mchId_channl);
			bean.setBizKey("自动化测试bizKey_"+TestDataManager.getRandomIntNum(5));
			bean.setBizValue("自动化测试BizValue_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatus1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
	        interactionstateExample.createCriteria().andBizKeyEqualTo(bean.getBizKey()).andMchIdEqualTo(bean.getMchId());
	        interactionstate model=interactionstateWapper.selectByExample(interactionstateExample).get(0);
	        Logger.verifyEquals(bean.getBizValue(), model.getBizValues(), "验证BizValue");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setInteractionState_002() {
		Logger.start(true,"正例-设置前端交互状态-BizKey相同,更新BizValue返回成功");
		try {
			String bizKey="自动化测试bizKey_"+TestDataManager.getRandomIntNum(5);
			//创建渠道
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			bean.setMchId(mchId_channl);
			bean.setBizKey(bizKey);
			bean.setBizValue("自动化测试BizValue_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			
			bean.setBizKey(bizKey);
			bean.setBizValue("自动化测试BizValue_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			
			Logger.verifyEquals("200", call.getStatus1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
	        interactionstateExample.createCriteria().andBizKeyEqualTo(bean.getBizKey()).andMchIdEqualTo(bean.getMchId());
	        interactionstate model=interactionstateWapper.selectByExample(interactionstateExample).get(0);
	        Logger.verifyEquals(bean.getBizValue(), model.getBizValues(), "验证BizValue");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setInteractionState_003() {
		Logger.start(true,"正例-设置前端交互状态-mchId为空-返回成功");
		try {
			//创建渠道
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			//bean.setMchId(mchId_channl);
			bean.setBizKey("自动化测试bizKey_"+TestDataManager.getRandomIntNum(5));
			bean.setBizValue("自动化测试BizValue_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("4001", call.getStatus1(), "验证返回成功status值");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setInteractionState_004() {
		Logger.start(true,"正例-设置前端交互状态-BizKey为空-返回成功");
		try {
			//创建渠道
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			bean.setMchId(mchId_channl);
		//	bean.setBizKey("自动化测试bizKey_"+TestDataManager.getRandomIntNum(5));
			bean.setBizValue("自动化测试BizValue_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("4001", call.getStatus1(), "验证返回成功status值");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setInteractionState_005() {
		Logger.start(true,"正例-设置前端交互状态-BizValue为空-返回成功");
		try {
			//创建渠道
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			bean.setMchId(mchId_channl);
			bean.setBizKey("自动化测试bizKey_"+TestDataManager.getRandomIntNum(5));
			//bean.setBizValue("自动化测试BizValue_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("4001", call.getStatus1(), "验证返回成功status值");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_setInteractionState_006() {
		Logger.start(true,"正例-设置前端交互状态-mchId不存在-返回失败(开发这边没有对mchid验证)");
		try {
			//创建渠道
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			bean.setMchId(mchId_channl);
			bean.setBizKey("自动化测试bizKey_"+TestDataManager.getRandomIntNum(5));
			bean.setBizValue("自动化测试BizValue_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatus1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
//	        interactionstateExample.createCriteria().andBizKeyEqualTo(bean.getBizKey()).andMchIdEqualTo(bean.getMchId());
//	        interactionstate model=interactionstateWapper.selectByExample(interactionstateExample).get(0);
//	        Logger.verifyEquals(bean.getBizValue(), model.getBizValues(), "验证BizValue");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}